<?php
require_once "includes/common.php";
require_once ('includes/header.php');

$id = isset($_GET['id'])?$_GET['id']:0;


// Fetch User from database
$resource = fetchById('users',$id);
$user_data = mysql_fetch_assoc($resource);

?>
<div class="hero-unit">
  <h4>Edit Users Profile</h4>
</div>

<div class="row-fluid">
  <form enctype="multipart/form-data"   name="register" method="post" id="registerId" action="edit_saveuser.php">
<input type="hidden" name="id" value="<?=$user_data['id'] ?>">
      <table border="0" cellspacing="0" align="center" width="80%">
        <thead>
          <tr>
            <th colspan="2">Please update the details below</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td width="40%" align="right">Name :</td>
            <td>
             <input type="text" name="uname"
              placeholder="My Name is.." value="<?=$user_data['uname']?>"/></td>
          </tr>

          <tr>
            <td align="right">Email :</td>
            <td>
               <input type="text" name="email"
               placeholder="example@example.com" value="<?=$user_data['email']?>" ></td>
          </tr>

          <tr>
            <td align="right">Date Of Birth :</td>
            <td><input name="dob" value="<?=$user_data['dob']?>" type="date" placeholder="YYYY/MM/DD"/></td>
          </tr>

          <tr>
            <td align="right">Address :</td>
            <td><textarea name="address" placeholder="My Address is.."><?=$user_data['address']?></textarea></td>
          </tr>

          <tr>
            <td align="right">Country :</td>
            <td>
              <select name="country">
                <option value="">-Select-</option>
      <?php 
      $countries = fetchAll('countries');
      while($country  =  mysql_fetch_assoc($countries)) { 
      $isSelected = 	($user_data['country'] == $country['c_code']) ? 'selected':'';
      ?>      	
		        <option <?=$isSelected?> value="<?=$country['c_code']?>"><?=$country['name']?></option>
      <?php } ?>
      
              </select>
            </td>
          </tr>

          <tr>
            <td align="right">Gender :</td>
            <td>
            	<?php 
            	$isMale = ($user_data['gender'] == 0) ? 'checked':'';
				$isFemale = ($user_data['gender'] == 1) ? 'checked':''; 
            	?>
              <label><input type="radio" <?=$isMale?> value="0" name="gender"/>Male</label>
              <label><input type="radio" <?=$isFemale?> value="1"  name="gender"/>Female</label>
              <label for="gender" generated="true" class="error"></label>
            </td>
          </tr>


          <tr>
            <td align="right">Language :</td>
            <td>
              <select multiple name="lang[]">
      <?php foreach(languages() as $k=>$v) {
      		$databaseLangArray = explode(',',$user_data['lang']);  
      	    $isSelected = 	in_array( $k ,$databaseLangArray) ? 'selected':'';
      	?>
      			<option <?=$isSelected?> value="<?=$k?>"><?=$v?></option>
      <?php }?>	
              </select>
            </td>
          </tr>

          <tr>
            <td align="right">Hobbies :</td>
            <td><?php 
                 $databaseHobbiesArray = explode(',',$user_data['hobbies']);
            	
            	?>
              <label><input <?=in_array( 'cricket' ,$databaseHobbiesArray) ? 'checked':''?> type="checkbox" value="cricket" checked name="hobbies[]"/>Cricket</label>
              <label><input <?=in_array( 'football' ,$databaseHobbiesArray) ? 'checked':''?> type="checkbox" value="football"  name="hobbies[]"/>Football</label>
              <label><input <?=in_array( 'hockey' ,$databaseHobbiesArray) ? 'checked':''?> type="checkbox" value="hockey" checked name="hobbies[]"/>Hockey</label>
              <label><input <?=in_array( 'others' ,$databaseHobbiesArray) ? 'checked':''?> value="others" type="checkbox" name="hobbies[]"/>Others</label><br>
              <label for="hobbies[]" generated="true" class="error" style=""></label>
            </td>
          </tr>

          <tr>
            <td align="right">Avatar :</td>
            <td><input name="avatar" type="file"/></td>
          </tr>

          <tr>
            <td align="right">&nbsp;</td>
            <td><input value="I am done!!" type="submit"/></td>
          </tr>

        </tbody>
      </table>
   </div>
<?php
require_once ('includes/footer.php');
?>
